home *** CD-ROM | disk | FTP | other *** search
- /* This function is from "The C Toolbox" by William James Hunt */
- /* (Addison-Wesley, 1985) */
-
- /* getstr.c - get a line of input from keyboard */
- /* like fgets(...stdin) but doesnot place the '\n' in the string */
-
- #include <stdio.h>
-
- int getstr(s,maxs) /* get a line of input */
- char s[] ; /* place the input here in string form */
- int maxs ; /* limit on characters allowed */
- { /* returns string length */
- int i , c ;
-
- i=0 ;
- c = getchar() ; /* get first character */
- /* repeat til full, EOF or end-of-line */
- while( (i < maxs) && (c != '\n') && ( c != EOF) )
- { s[i] = c ; /* place char in string */
- i = i + 1 ; /* advance char count */
- c = getchar() ; /* and get another character */
- }
- s[i] = '\0' ;
- return( i ) ; /* return count of characters */
- }